import 'package:flutter/material.dart';

class EzImage extends StatelessWidget {
  final String path;
  final double? height;
  final double? width;
  final BoxFit fit;
  final Alignment alignment;
  final bool isAsset;

  ///本地图片资源
  const EzImage.asset(this.path,
      {Key? key,
      this.height,
      this.width,
      this.fit = BoxFit.fill,
      this.alignment = Alignment.center})
      : isAsset = true,
        super(key: key);

  ///网络图片资源
  const EzImage.network(this.path,
      {Key? key,
      this.height,
      this.width,
      this.fit = BoxFit.fill,
      this.alignment = Alignment.center})
      : isAsset = false,
        super(key: key);

  String _assetPrefix(String path) {
    return "assets/images/$path";
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: height,
      width: width,
      child: isAsset
          ? Image.asset(
              _assetPrefix(path),
              fit: fit,
              alignment: alignment,
            )
          : Image.network(
              path,
              fit: fit,
              alignment: alignment,
            ),
    );
  }
}
